<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        调整阶段
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="../../../../js/xm-select.js"></script>

</head>

<style>
    .layui-form-label {
        width: 150px !important;
    }
</style>

<body>

<div class="x-body" id="app">



    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <label class="layui-form-label"><span class='x-red'>*</span>阶段名称</label>
                <div class="layui-input-inline">
                    <select name="stageId" id="stageId" lay-search="">
                        <option value="">选择阶段</option>
                    </select>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>原因</label>
                    <div class="layui-input-inline w60">
                        <input  autocomplete="off"  type="text" name="dealReason" v-model="sjname"
                               lay-verify="required" placeholder="修改的原因" class="layui-input">
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                       修改
                    </button>
                </div>
                <!--</form>-->


                <div style="height:20px;"></div>
            </div>


        </div>

    </form>

</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        element = layui.element;//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var Id = getQueryVariable("Id");

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            getProject();


            function getProject(){
                // document.getElementById("projectId").innerHTML = "";
                $.ajax({
                    type:"get",
                    url:baseHead + "xa/projectTemplate/findProjectStageByLevel",
                    data:{
                        userId :$userId,
                        level: 2,
                        projectId:Id
                    },
                    headers: {
                        "token": $token,
                    },
                    success:function(res){
                        console.log(res);
                        if(res.code == 0){
                            // $("#projectId").append("<option value=''>请选择关联项目</option>");
                            for(var i =0;i < res.data.length;i++){
                                $("#stageId").append("<option value=\""+res.data[i].id+"-"+res.data[i].name+"\">"+res.data[i].name+"</option>");
                            }
                            //重新渲染
                            layui.form.render("select");
                        }else{
                            layer.msg(res.message);
                        }
                    }
                });
            };




            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.projectId=Id;
                    form.operatorId=$userId;
                    form.userId=$userId;
                    form.stageName =form.stageId.split('-')[1];
                    form.stageId =  form.stageId.split('-')[0];

                    console.log(form);
                    let request = {
                        url: 'xa/project/updateProjectStage',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.location.reload();
                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });


        });




</script>

</body>

</html>
